#include <iostream>
#include <string>
#include <limits>

using std::cout;
using std::cerr;
using std::endl;
using std::cin;
using std::istream;
using std::string;

void printStreamStatus(istream &is)
{
    cout << "goodbit = " << is.good() << endl
         << "badbit = " << is.bad() << endl
         << "failbit = " << is.fail() << endl
         << "eofbit = " << is.eof() << endl;
}

void test()
{
    int number = 0;
    printStreamStatus(cin);
    cin >> number;
    printStreamStatus(cin);
    cin.clear();//重置流的状态
    /* cin.ignore(1024, '\n');//清空缓冲区 */
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//清空缓冲区
    printStreamStatus(cin);

    cout << "number = " << number << endl;

    string s1;
    printStreamStatus(cin);
    cin >> s1;
    cout << "s1 = " << s1 << endl;
}

void test2()
{
    int number = 0;
    //逗号表达式
    while(cin >> number, !cin.eof())//ctrl + d
    {
        if(cin.bad())//无法恢复的错误
        {
            cerr << "The stream is bad" << endl;
            return;
        }
        else if(cin.fail())
        {
            cin.clear();//重置流的状态
            cin.ignore(std::numeric_limits<std::streamsize>::max(),
                       '\n');//清空缓冲区
            cout << "pls input int data" << endl;
        }
        else
        {
            cout << "number = " << number << endl;
        }
    }
}

int main(int argc, char *argv[])
{
    test2();
    return 0;
}

